package com.oocl.o2o.merchant.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.oocl.o2o.merchant.service.MerchantManager;
import com.oocl.o2o.merchant.vo.AuditInfo;

public class AuditInterceptor implements HandlerInterceptor {
	@Autowired
	private MerchantManager merchantManger;

	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		String username = (String) session.getAttribute("username");
		AuditInfo auditInfo = merchantManger.getAuditInfo(username);
		if(auditInfo==null||auditInfo.getStatus()!=1) {
			response.sendRedirect("/o2o-merchant/sec/merchant");
			return false;
		}
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}

}
